package com.cash.app.utils

import android.annotation.SuppressLint
import java.text.NumberFormat
import kotlin.math.roundToInt

object NumberUtils {

    /**
     * Converts cents to rupees string without decimal places
     * @param centMoney Amount in cents
     * @return Formatted amount string in rupees
     */
    @SuppressLint("DefaultLocale")
    fun toRupee(centMoney: Int): String {
        val rupees = centMoney / 100.0
        return String.format("%.0f", rupees)
    }

    /**
     * Formats rupees amount with comma separator using system locale
     * @param centMoney Amount in cents
     * @return Formatted amount string with comma separator (e.g. "1,000")
     */
    fun toRupeeWithComma(centMoney: Int): String {
        val rupees = centMoney / 100
        return NumberFormat.getNumberInstance().format(rupees)
    }

    /**
     * Converts amount from rupees to cents
     * @param money Amount in rupees (double precision)
     * @return Amount in cents as long integer
     */
    fun toCent(money: Double): Long {
        return (money * 100).roundToInt().toLong()
    }

    /**
     * Masks bank card number by replacing all but last 4 digits with asterisks
     * @param cardNumber Full bank card number
     * @return Masked card number (e.g. "************1234") or empty string if input is null/empty
     */
    fun maskBankCard(cardNumber: String?): String {
        if (cardNumber.isNullOrEmpty()) return ""
        if (cardNumber.length <= 4) return cardNumber
        return "*".repeat(cardNumber.length - 4) + cardNumber.takeLast(4)
    }
} 